package com.huike.clues.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.clues.domain.TbCourse;
import com.huike.clues.domain.dto.TbCourseDTO;
import com.huike.clues.domain.dto.mydto.CourseQueryDTO;
import com.huike.clues.service.TbCourseService;
import com.huike.clues.mapper.TbCourseMapper;
import com.huike.common.utils.uuid.UUIDUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author 93238
 * @description 针对表【tb_course(课程管理)】的数据库操作Service实现
 * @createDate 2023-10-12 06:35:46
 */

/**
 * 课程管理实现类
 */
@Service
public class TbCourseServiceImpl extends ServiceImpl<TbCourseMapper, TbCourse>
        implements TbCourseService {


    /**
     * 新增课程管理
     *
     * @param tbCourseDTO
     * @return
     */
    @Override
    public boolean addTbCourse(TbCourseDTO tbCourseDTO) {
        TbCourse tbCourse = BeanUtil.toBean(tbCourseDTO, TbCourse.class);
        tbCourse.setCode(UUIDUtils.getUUID());
        return this.save(tbCourse);
    }

    /**
     * 修改课程管理
     *
     * @param tbCourseDTO
     */
    @Override
    public boolean updateTbCourse(TbCourseDTO tbCourseDTO) {
        TbCourse tbCourse = BeanUtil.toBean(tbCourseDTO, TbCourse.class);
        return this.updateById(tbCourse);
    }

    /**
     * 分页查询课程管理信息
     *
     * @param courseQueryDTO
     */
    @Override
    public List<TbCourse> selectTbCourseList(CourseQueryDTO courseQueryDTO) {
        List<TbCourse> tbCourseList = this.list(Wrappers.<TbCourse>lambdaQuery()
                .like(StringUtils.isNotBlank(courseQueryDTO.getCode()), TbCourse::getCode, courseQueryDTO.getCode())
                .like(StringUtils.isNotBlank(courseQueryDTO.getName()), TbCourse::getName, courseQueryDTO.getName())
                .eq(StringUtils.isNotBlank(courseQueryDTO.getApplicablePerson()), TbCourse::getApplicablePerson, courseQueryDTO.getApplicablePerson())
                .between(ObjectUtils.isNotEmpty(courseQueryDTO.getParams().get("beginCreateTime")) && ObjectUtils.isNotEmpty(courseQueryDTO.getParams().get("endCreateTime")), TbCourse::getCreateTime, courseQueryDTO.getParams().get("beginCreateTime"), courseQueryDTO.getParams().get("endCreateTime"))
                .like(StringUtils.isNotBlank(courseQueryDTO.getSubject()), TbCourse::getSubject, courseQueryDTO.getSubject())
                .orderByDesc(TbCourse::getCreateTime));
        return tbCourseList;
    }

    /**
     * 课程下拉列表
     *
     * @param subject
     */
    @Override
    public List<TbCourse> selectTbCourseSubject(String subject) {
        return this.list();
    }

    /**
     * 删除课程管理
     *
     * @param ids
     */
    @Override
    public boolean delectTbCourse(Long[] ids) {
        return removeByIds(Arrays.asList(ids));
    }

    /**
     * 查询课程管理详细信息
     *
     * @param id
     */
    @Override
    public TbCourse selectTbCourse(Long id) {
        return getById(id);
    }
}




